﻿using System;
using System.Threading;
using InspectionMAC.SystemThread;
using InspectionMAC;
using System.Drawing;
using System.Drawing.Imaging;
using InspectionMAC.Algorithm;

public class CameraTriggerService
{
    public static Thread Camera_Thread = null;
    public static int CameraImgGet_Step = 0;
    public static bool CameraTrigger_Flowrec = false;

    public static void CameraImgGet_Thread()
    {
        CameraTrigger_Flowrec = true;
        Camera_Thread = new Thread(CameraImgGetThread);
        Camera_Thread.IsBackground = true;
        Camera_Thread.Start();
        CameraImgGet_Step = 1;
        Console.WriteLine("工位1线程已启动");
    }

    public static void StopThread()
    {
        CameraTrigger_Flowrec = false;
        if (Camera_Thread != null && Camera_Thread.IsAlive)
        {
            if (!Camera_Thread.Join(1000))
            {
                Camera_Thread.Interrupt();
            }
        }
        Console.WriteLine("线程已停止");
    }
    private static void CameraImgGetThread(object obj)
    {
        Console.WriteLine("线程开始运行");

        while (CameraTrigger_Flowrec)
        {
            
                switch (CameraImgGet_Step)
                {
                    case 1:
                    TestDioThread.iTestDio_Step = 45;
                    break;

                    case 5:

                    ////CameraReceiveThread_01.device.Parameters.SetCommandValue("TriggerSoftware");
                    //GetCameraImgThread01.CameraImgGet_Step = 5;
                    ////GetCameraImgThread101.CameraImgGet_Step = 5;
                    ////CameraReceiveThread_02.device.Parameters.SetCommandValue("TriggerSoftware");
                    //GetCameraImgThread02.CameraImgGet_Step = 5;
                    ////GetCameraImgThread102.CameraImgGet_Step = 5;
                    ////CameraReceiveThread_03.device.Parameters.SetCommandValue("TriggerSoftware");
                    //GetCameraImgThread03.CameraImgGet_Step = 5;
                    ////GetCameraImgThread103.CameraImgGet_Step = 5;
                    break;

                case 10:
                    Thread.Sleep(5000);
                    CameraImgGet_Step = 5;
                    break;
                }
            
        }
    }
}